package com.woniuxy.springparking.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.springparking.common.RestResult;
import com.woniuxy.springparking.dao.LogDao;
import com.woniuxy.springparking.pojo.Log;
import com.woniuxy.springparking.service.LogService;
import com.woniuxy.springparking.vo.LogVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogDao logDao;

    @Override
    public void saveLog(Log log) {
        logDao.insert(log);
    }

    @Transactional
    @Override
    public void removeLog(Integer id) {
       logDao.deleteById(id);
    }

    @Transactional
    @Override
    public void removeManyLog(Integer[] ids) {
        for (Integer id:ids){
            this.removeLog(id);
        }
    }


    @Override
    public RestResult findByPage(LogVO vo) {
        Page<Object> pages= PageHelper.startPage(vo.getPage(),vo.getLimit());
        List<Log> data=this.logDao.selectByPage(vo);
        return new RestResult(pages.getTotal(),data);
    }

    @Override
    public void insertLog(Log log) {
        this.logDao.insert(log);
    }
}
